var orderInfo;
var couponNum=''
function orderSheetOnLoad() {
    if(orderData == null || orderData == '') return;
    orderInfo = JSON.parse(orderData);
    /* 根据status状态，进行不同处理,送检单状态：1未确认；  2 已确认，无法编辑 ; 0 默认值*/
    /* 0：空白页进行填写，1：有数据，进行编辑*/
    if(orderInfo.status==1)
    {
        setValues();
    }

}
$(document).ready(function (){
    $('#coupon_icon').hide()
    initUrlInfo();
    queryCoupon();
    searchCustom();
})
function countYun(obj) {
    var date = new Date($(obj).val()).getTime();
    var today = new Date().getTime();
    var totalDays = (today - date) / (1000 * 60 * 60 * 24 * 1);
    var week = parseInt(totalDays / 7);
    var day = parseInt(totalDays % 7);
    $("#gttWeek").val(week);
    $("#gttDay").val(day);
    checkGttWeek('gttWeek');
    checkGttDay('gttDay');
    $("#gestationalWeeks").val(week+'+'+day);
}

function triggerDate()
{
    $("#lastPeriod").trigger('click');
}

function triggerArea()
{
    $("#area-opt").trigger('click');
}
function checkHeight() {
    if($("div:contains('身高(厘米)')").length==0) return true;
    var text = $.trim($("#height").val());
    // alert(text);
    if (text.length == 0) {
        tipsMsg('heightnone');
        return false;
    }

    roundNum("#height");

    if (!checkNumber('height', 0, 250)) {
        tipsMsg('height');
        $("#height").css('color', 'red');
        $("#height-tips").css('display', 'inline');
        return false;
    }
    else {
        $("#height").css('color', '#333');
        $("#height-tips").css('display', 'none');
    }

    return true;
}

function checkGestatidon() {
    var zrsy = $('input[name=zrsy]').val();
    var cpl = $('input[name=cpl]').val();
    var gnrgsy = $('input[name=gnrgsy]').val();

    if(zrsy=='${orderInfo.zrsy}' || cpl=='${orderInfo.zrsy}' || gnrgsy=='${orderInfo.zrsy}') {
        tipsMsg('gestationnone');
        return false;
    }
    return true;
}

function parseArea() {
    var area = $("#area-value").val();
    if (area == "") {
        // alert("请选择城市");
        return false;
    }
    var patten = /(\d{2})0000,(\d{4})00,(\d{6})|(\d{2})0000/g;
    var result = patten.exec(area);
    if (result != null) {
        if (result[4] == undefined) {
            $("#province").val(result[1]);
            $("#city").val(result[2]);
            $("#county").val(result[3]);
        }
        else {
            $("#province").val(result[4]);
            $("#city").val("");
            $("#county").val("");
        }
        return true;
    }
}


var tipTexts = {};
tipTexts.shuxue="异体输血是指孕妇接受过他人全血或血成分（如红细胞、血小板等）的静脉输注的行为。一年内接受过异体输血的孕妇不可做此检测。";
tipTexts.shuxueyes="一年内接受过异体输血的孕妇不可做此检测，请联系医生或医院相关工作人员。";

tipTexts.yizhi="移植手术是指孕妇接受过来源于他人器官（如心脏、肺脏、肝脏、肾脏等）移植入体内的行为，接受过移植手术的孕妇不可做此检测。";
tipTexts.yizhiyes="接受过移植手术的孕妇不可做此检测，请联系医生或医院相关工作人员。";

tipTexts.mianyi="免疫治疗是指孕妇接受过引入外源DNA的治疗（如皮下注射他人淋巴细胞），一个月内接受过免疫治疗的孕妇不可做此检测。";
tipTexts.mianyiyes="一个月内接受过免疫治疗的孕妇不可做此检测，请联系医生或医院相关工作人员。";

tipTexts.gxb="干细胞治疗是指通过特殊的移植手术将干细胞移植到孕妇体内的行为，接受过干细胞治疗的孕妇不可做此检测。";
tipTexts.gxbyes="接受过干细胞治疗的孕妇不可做此检测，请联系医生或医院相关工作人员。";

tipTexts.phone="手机号码填写有误，请在相应位置重新填写。";
tipTexts.idnumber="身份证号码填写有误，请在相应位置重新填写。";

tipTexts.phonenone="请在相应位置填写孕妇手机号码。";
tipTexts.idnumbernone="请在相应位置填写孕妇身份证号码。";

tipTexts.icephonenone="请在相应位置输入丈夫的手机号码。";
tipTexts.icephone="号码填写有误，请在相应位置输入紧急联系人的手机号码。";

tipTexts.name="请在相应位置填写孕妇姓名。";

tipTexts.gttweek="检测最佳孕周为12周+0天至26周+6天，不在此孕周范围的孕妇请联系医生或医院相关工作人员。";
tipTexts.gttday="检测最佳孕周为12周+0天至26周+6天，不在此孕周范围的孕妇请联系医生或医院相关工作人员。";
tipTexts.weight="请正确填写孕妇体重，其数值为整数。体重在100公斤以上的孕妇不能做此检测，请联系医生或医院相关工作人员。";

tipTexts.gttweeknone="请在相应位置填写孕妇孕周。";
tipTexts.gttdaynone="请在相应位置填写孕妇孕周。";
tipTexts.gttweeklarge="大孕周孕妇可做此检测，但需在“大孕周知情同意书”签名同意，具体请咨询事务或医院相关工作人员。";
tipTexts.weightnone="请在相应位置填写孕妇体重。";
tipTexts.location="请在相应位置选择孕妇所在地。";
tipTexts.bscannone="请在相应位置填写孕妇B超结果。";
tipTexts.bscan_4="多胎孕妇不能做此检测，请联系医生或医院相关工作人员。";
tipTexts.bscan_2="单胎异常孕妇不能做此检测，请联系医生或医院相关工作人员。";
tipTexts.bscan_3="双胎异常孕妇不能做此检测，请联系医生或医院相关工作人员。";

tipTexts.shuxuenone="请在相应位置选择孕妇一年内是否有过异体输血。";
tipTexts.mianyinone="请在相应位置选择孕妇是否有接受过免疫治疗。";
tipTexts.yizhinone="请在相应位置选择孕妇是否有接受过移植手术。";
tipTexts.gxbnone="请在相应位置选择孕妇是否接受过干细胞治疗。";

tipTexts.ges="孕次填写有误，请重新填写（孕次超过10次请填写为10次）。";
tipTexts.abo="产次填写有误，请重新填写（产次超过10次请填写为10次）。";
tipTexts.lab="人流次数填写有误，请重新填写（人流次数超过10次请填写为10次）。";

tipTexts.ivfnone="请填写您本次怀孕是否为人工授精，如有疑问请联系医生或医院相关工作人员。";
tipTexts.ivferror="男女任何一方核型检测异常均不可做此检测，请联系医生或医院相关工作人员。";
tipTexts.ivfmalenone="请选择男方核型检测结果，如未做请选择未知。";
tipTexts.ivffemalenone="请选择女方核型检测结果，如未做请选择未知。";
tipTexts.downmodelnone="请在相应位置选择唐筛模式。";
tipTexts.citynone="请在相应位置选择检测医院所在城市";
tipTexts.hospitalnone="请在相应位置选择检测医院名称";

tipTexts.downmodelnum="请在相应位置填写唐筛检测结果。";
tipTexts.downmodelnumerror="请正确填写唐筛检测结果，其结果为唐筛风险值。";
tipTexts.heightnone = "请在相应位置填写身高。";
tipTexts.height = "请正确填写孕妇身高值，其数值为整数。";
tipTexts.lastPeriodnone="请在相应位置选择末次月经日期。";


tipTexts.passport = "护照填写有误，请在相应位置重新填写。";
tipTexts.age = "年龄填写有误,请在相应位置重新填写。";
tipTexts.agenone = "请在相应位置填写年龄。";
tipTexts.bscanremarklength = "B超备注超出长度,请重新填写。";
tipTexts.ivfmaleremarklength = "男方染色体备注超出长度,请重新填写。";
tipTexts.ivffemaleremarklength = "女方染色体备注超出长度,请重新填写。";
tipTexts.ivfremark1none = "请在IVF的相应问题中填写，否则不能提交表单，如有问题请询问医生或医院相关工作人员。";
tipTexts.ivfremark2none = "请在IVF的相应问题中填写，否则不能提交表单，如有问题请询问医生或医院相关工作人员。";
tipTexts.ivfremark3none = "请在IVF的相应问题中填写，否则不能提交表单，如有问题请询问医生或医院相关工作人员。";
tipTexts.ivfremark4none = "请在IVF的相应问题中填写，否则不能提交表单，如有问题请询问医生或医院相关工作人员。";
tipTexts.ivfmore = "胚胎植入3胎或以上的孕妇不可做此检测，请联系医生或医院相关工作人员。";
tipTexts.ivferror = "一胎发育异常的孕妇不可做此检测，请联系医生或医院相关工作人员。";
tipTexts.ivflose = "胚胎丢失时已在孕8周以上的孕妇不可做此检测，请联系医生或医院相关工作人员。";
tipTexts.ivfstop = "距停育后继续妊娠不足8周的孕妇不可做此检测，请联系医生或医院相关工作人员。";
tipTexts.gestationnone = "请选择本次妊娠形式，如有问题请联系医生或医院相关工作人员。";

var iPhone = (navigator.userAgent.match(/iPhone/i));
var iPod = navigator.userAgent.match(/iPod/i);
var Android = navigator.userAgent.match(/Android/i);

var selectedTownId = "pd";
var selectedBscanId = "NA";

//打开选择浮层
function openSelectTip(tipId){
    $("#fade").css('display','block');
    $("#"+tipId).css('display','block');

    $(function(){
        $("#fade").click(function(event){
            var id = event.target.id;
            if( id == 'fade'){ closeSelTips(tipId); }
        });
    });
}

//关闭遮罩层  关闭选择框   注销body click事件
function closeSelTips(tipId){
    selClose(tipId);
    selClose('fade');
    //解除绑定
    $("#fade").unbind('click');
}

function selClose(id){
    $("#"+id).css('display','none');
}

function transX(obj) {
    var id = $.trim($(obj).val());
    var patten = /^(\d){17}x$/ig;
    if(patten.test(id))
    {
        var transId = id.replace("x","X");
        $(obj).val(transId);
    }
}

function selTown(obj, divId){
    var id = obj.id;
    var value = $("#"+id).data("value") ;
    var input_value = $("#"+id).data("input");

    //填写地区code和地址信息
    $("#"+divId+"-input").val(input_value);

    if(id != selectedTownId){
        $("#"+id).addClass("selected");
        $("#"+selectedTownId).removeClass("selected");
        selectedTownId = id;
    }
    // alert(value);
    $("#"+divId+"-value").text(value);
    $("#"+divId+"p").css('color','#333');
    closeSelTips(divId);
    if(divId === 'hospitalCity')
    {
        if($("#hospitalSelectDiv").hasClass("hidden"))
        {
            $("#hospitalSelectDiv").removeClass("hidden");
            $("#hospitalSelectDiv-line").removeClass("hidden");
        }
        else
        {
            $("#hospitalSelect-value").text("");
            $("#hospitalSelect-input").val("");
            $("#fswid-input").val("");
            $("#customer-code-input").val("");
            $("#customer-name-input").val("");
        }
        genHospitalSelect(input_value);
    }
}

function selHospital(obj, divId, fswid, code, name){
    var id = obj.id;
    var value = $("#"+id).data("value") ;
    var input_value = $("#"+id).data("input");

    //填写地区code和地址信息
    $("#"+divId+"-input").val(input_value);
    $("#fswid-input").val(fswid);
    $("#customer-code-input").val(code);
    $("#customer-name-input").val(name);
    if(id != selectedTownId){
        $("#"+id).addClass("selected");
        $("#"+selectedTownId).removeClass("selected");
        selectedTownId = id;
    }
    // alert(value);
    $("#"+divId+"-value").text(value);
    $("#"+divId+"p").css('color','#333');
    closeSelTips(divId);
}

function genHospitalSelect(city) {
    $("#hospitalList").empty();
    var i = 0;
    var data = JSON.parse(hospitalData);
    for(i in data)
    {
        var item = data[i];
        if(item.city == city)
        {
            var node = "<li id=\""+item.code+"\" data-value=\""+item.name+"\" data-input=\""+item.code
                +"\" class=\"sel-info\" onclick=\"selHospital(this, 'hospitalSelect', '"+item.bgiRegion.busKey+"','"
                +item.code+"','" +item.name+"');\">"+item.name+"</li>";
            node += " <div class=\"input-line\"></div>";
            $("#hospitalList").append(node);
        }
    }
}

//选择B超结果
function selBscan(obj){
    var id = obj.id;
    var value = $("#"+id).data("value") ;
    var input_value = $("#"+id).data("input");
    $("#bscan-input").val(input_value);

    if( id != selectedBscanId ){
        $("#"+id).addClass("selected");
        $("#"+selectedBscanId).removeClass("selected");
        selectedBscanId = id;
    }
    //alert(value);
    $("#bscan-value").text(value);
    $("#bscan").css('color','#333');
    //关闭B超浮层
    closeSelTips('bscanSel');
    $("#bscan-tips").css('display','none');
    $("#bscan-sel-note").css('display','none');
    if(id=='bscan-4'){
        tipsMsg('bscan_4');
        $("#bscan").css('color','red');
        $("#bscan-tips").css('display','inline');
    }
    if(id=='bscan-2'){
        tipsMsg('bscan_2');
        $("#bscan").css('color','red');
        $("#bscan-tips").css('display','inline');
    }

    if(id=='bscan-3'){
        tipsMsg('bscan_3');
        $("#bscan").css('color','red');
        $("#bscan-tips").css('display','inline');
    }

    if(id=='bscan-1'){
        var needOtherReport = $("#needOtherReport").val();
        if(needOtherReport!=='')$("#needOtherReport").val(0);
    }
}

//选择唐筛模式
var selectedDownModelId = "NA";
function selDownModel(obj){
    var id = obj.id;
    var value = $("#"+id).data("value") ;
    var input_value = $("#"+id).data("input");

    if( id != selectedDownModelId ){
        $("#"+id).addClass("selected");
        $("#"+selectedDownModelId).removeClass("selected");
        selectedDownModelId = id;
    }
    //alert(value);
    $("#downModel-value").text(value);
    $("#downModel").css('color','#333');
    $("#down-model-input").val(input_value);
    $("#down-sel-note").css('display','none');
    //显示二级表单
    if(id == "down-1"){
        $("#downModelSubEarly").css('display','block');
        $("#downModelSubMiddle").css('display','none');
    }
    else if(id == "down-2")
    {
        $("#downModelSubMiddle").css('display','block');
        $("#downModelSubEarly").css('display','none');
    }
    else if(id == "down-3")
    {
        $("#downModelSubEarly").css('display','block');
        $("#downModelSubMiddle").css('display','block');
    }
    else
    {
        $("#downModelSubEarly").css('display','none');
        $("#downModelSubMiddle").css('display','none');
    }

    $("#earlydown21").val("");
    $("#earlydown18").val("");
    $("#earlyntd").val("");
    $("#middledown21").val("");
    $("#middledown18").val("");
    $("#middlentd").val("");
    //关闭浮层
    closeSelTips('downModelSel');
}

//选择人工授精IVF：selIvf
var selectedIVFId = "NA";//选择的内容
function selIvf(obj, ivfSel){
    var id = obj.id;
    var value = $("#"+id).data("value") ;
    var input_value = $("#"+id).data("input");

    if( id != selectedIVFId ){
        $("#"+id).addClass("selected");
        $("#"+selectedIVFId).removeClass("selected");
        selectedIVFId = id;
    }
    //赋值
    $("#ivf-male-value").text(value);
    $("#ivf-male-value").css('color','#333');
    $("#ivf-male-input").val(input_value);
    $("#ivf-male-sel-note").css('display','none');
    //关闭浮层
    closeSelTips(ivfSel);
    $("#ivf-male-tips").css('display','none');
    if(id=='ivf-2'){
        $("#ivf-male-value").css('color','red');
        $("#ivf-male-tips").css('display','inline');
    }
    checkIvfError();
}

function selGestation(obj) {
    var value = $(obj).data("value");
    var input = $(obj).data("input");
    var sel = $(obj).parents(".select_content");
    sel.find(".selected").removeClass("selected");
    $(obj).addClass("selected");
    $("#gestation-sel-note").hide();
    $("#gestation-value").text(value);
    $("#pregnancy").val(input);
    closeSelTips('gestationSel');
}
//女方选择
var selectedFemaleIVFId = "NA";//选择的内容
function selFemaleIvf(obj, ivfSel){
    var id = obj.id;
    var value = $("#"+id).data("value") ;
    var input_value = $("#"+id).data("input");

    if( id != selectedFemaleIVFId ){
        $("#"+id).addClass("selected");
        $("#"+selectedFemaleIVFId).removeClass("selected");
        selectedFemaleIVFId = id;
    }
    //赋值
    $("#ivf-female-value").text(value);
    $("#ivf-female-value").css('color','#333');
    $("#ivf-female-input").val(input_value);
    $("#ivf-female-sel-note").css('display','none');
    //关闭浮层
    closeSelTips(ivfSel);
    $("#ivf-female-tips").css('display','none');
    if(id=='ivf-f-2'){
        $("#ivf-female-value").css('color','red');
        $("#ivf-female-tips").css('display','inline');
    }
    checkIvfError();
}

function tipsMsg(msgid){//打开提示框
    var tiptext = tipTexts[msgid];
    if(!tiptext) return;
    openTips(tiptext);
}
function openTips(tiptext){
    //alert("tiptext:" + tiptext);
    $("#tipmsg").text(tiptext);
    $("#fade").css('display','block');
    //alert("show tipDia");
    $("#tipDia").css('display','block');
}
function closeTips(){//关闭提示框
    $("#tipDia").css('display','none');
    $("#fade").css('display','none');
}
//页面往上移动，防止键盘遮挡输入框
function upbody(){
    if(iPhone){
        //alert("is ios");
        return;
    }
    $("#ban_bt").css('margin-bottom','60%');
    window.scrollTo(0,document.body.scrollHeight);
}
function upbody(id){
    if(iPhone){
        //alert("is ios");
        return;
    }
    $("#ban_bt").css('margin-bottom','60%');
    window.scrollTo(0, 150 );
}
////////////////////
//单选radio yes
function radioYes(id){
    $("#"+id+"-yes").attr("src","./images/order/radio-red.png");
    $("#"+id+"-no").attr("src","./images/order/radio-def.png");
    //////
    $("#"+id+"-tips").attr("src","./images/order/qs-tip-red.png");
    ///tips 提示
    var msgid = id+'yes';
    $("#"+id+"-input").val(1);
    tipsMsg(msgid);
}
//单选radio no
function radioNo(id){
    //var id = obj.id;
    $("#"+id+"-yes").attr("src","./images/order/radio-def.png");
    $("#"+id+"-no").attr("src","./images/order/radio-blue.png");
    $("#"+id+"-tips").attr("src","./images/order/qs-tip.png");
    $("#"+id+"-input").val(0);
}
//单选radio yes
function radioYesCom(id) {
    $("#" + id + "-yes").attr("src", "./images/order/radio-blue.png");
    $("#" + id + "-no").attr("src", "./images/order/radio-def.png");
    $("#" + id + "-input").val(1);
    if(id === "ivf")
    {
        $("#ivfRemarkSel-1").show();
    }
}
//单选radio no
function radioNoCom(id) {
    $("#" + id + "-yes").attr("src", "./images/order/radio-def.png");
    $("#" + id + "-no").attr("src", "./images/order/radio-blue.png");
    $("#" + id + "-input").val(0);
    if(id === "ivf")
    {
        $("#ivfRemarkSel-1").hide();
        $("#ivfRemark-1").val("");
        $("#ivfRemarkSel-1 img").attr("src", "./images/order/radio-def.png");
        $("#ivfRemarkSel-2").hide();
        $("#ivfRemarkSel-2 img").attr("src", "./images/order/radio-def.png");
        $("#ivfRemark-2").val("");
        $("#ivfRemarkSel-3").hide();
        $("#ivfRemark-3").val("");
        $("#ivfRemark-4").val("");
        $("#ivfRemarkSel-3 img").attr("src", "./images/order/radio-def.png");
    }
}

function test(){
    alert("test msg--");
}
//必填项
var requiredKeys = ['customerCode','bloodDate','sampleName','motherPhoneNum','idCard','sampleAge','gestationalWeeks','allogeneticTransfusion','surgicalTransplantation','cellularImmunity','stemCell','adosculation']
//检查表单提交
function checkForm(status){

    parseArea();

    doSubmit();
}

var submiting = false;
function doSubmit(){
    if(submiting) return;
    submiting = true;
    var params={};
    var formInputs = $('input.submit').each(function(index,element){//遍历class含submit的标签值
        var name = $(element).attr('name');
        if(name){
            params[name]=$(element).val();
        }
    });

    params.sourceType='2';
    if(couponNum){
        params.couponNum = couponNum;
    }
    params.productCode='BS0003';
    params.productName='两癌登记表';

    //设置模板文件，pc端送检单列表点击编辑才可以进入编辑界面
    params.fileVer = "temp/sample2.jsp";

    // alert(JSON.stringify(params));
    if($('input:radio[name="hemorrhage"]:checked').val() != undefined){
        params.hemorrhage = $('input:radio[name="hemorrhage"]:checked').val();
    }
    if($('input:radio[name="leucorrhea"]:checked').val() != undefined){
        params.leucorrhea = $('input:radio[name="leucorrhea"]:checked').val();
    }
    if($('input:radio[name="contraceptiveMethod"]:checked').val() != undefined){
        params.contraceptiveMethod = $('input:radio[name="contraceptiveMethod"]:checked').val();
    }
    if($("#contraceptiveYear").val() != ''){
        params.contraceptiveYear = $("#contraceptiveYear").val();
    }
    if($('input:radio[name="intrauterineDevice"]:checked').val() != undefined){
        params.intrauterineDevice = $('input:radio[name="intrauterineDevice"]:checked').val();
    }
    if($("#intrauterineDeviceYear").val() != ''){
        params.intrauterineDeviceYear = $("#intrauterineDeviceYear").val();
    }
    if($('input:radio[name="contraceptiveMethodOther"]:checked').val() != undefined){
        params.contraceptiveMethodOther = $('input:radio[name="contraceptiveMethodOther"]:checked').val();
    }
    if($('input:radio[name="cin"]:checked').val() != undefined){
        params.cin = $('input:radio[name="cin"]:checked').val();
    }
    if($('input:radio[name="cervicalCarcinoma"]:checked').val() != undefined){
        params.cervicalCarcinoma = $('input:radio[name="cervicalCarcinoma"]:checked').val();
    }
    if($("#cervicalCarcinomaText").val() != ''){
        params.cervicalCarcinomaText = $("#cervicalCarcinomaText").val();
    }
    if($('input:radio[name="genitalTractInfection"]:checked').val() != undefined){
        params.genitalTractInfection = $('input:radio[name="genitalTractInfection"]:checked').val();
    }
    if($("#genitalTractInfectionText").val() != ''){
        params.genitalTractInfectionText = $("#genitalTractInfectionText").val();
    }
    if($('input:radio[name="otherTumors"]:checked').val() != undefined){
        params.otherTumors = $('input:radio[name="otherTumors"]:checked').val();
    }
    if($("#otherTumors_text").val() != ''){
        params.otherTumors_text = $("#otherTumors_text").val();
    }
    console.log(params);
    $.ajax({
        type:"post",
        async:false,
        url:BASEURL+"/csfy/wx/createSampleBase.do",
        data:params,
        dataType:"json",
        success:function (data) {
            openTips('提交成功');
            $('body').html('<div style="margin-top:100px;text-align:center;color:#00ff00;font-size:30px;">送检单提交成功</div>')
            submiting = false;
        },
        error:function(data){
            alert('出错了!');
            submiting = false;
        }

    });
}
function roundNum(obj) {
    var num = $.trim($(obj).val());
    if (parseInt(num) !== num)
        $(obj).val(Math.round(num));
}

function formatLastPeriod(lastPeriod) {
    var patten = /(\d){8}/ig;
    if(patten.test(lastPeriod))
    {
        var year = lastPeriod.substr(0,4);
        var month = lastPeriod.substr(4,2);
        var day = lastPeriod.substr(6,2);
        $("#lastPeriod").val(year+"-"+month+"-"+day);
    }
}

function checkLastPeriod() {
    var lastPeriod = $("#lastPeriod").val();
    if(lastPeriod === '')
    {
        tipsMsg("lastPeriodnone");
        return false;
    }

    formatLastPeriod(lastPeriod);
    return true;
}

function isNumber(num){
    var n=$.trim(num);
    if( /^[1-9](\d+)?$/.test( n ) ){
        return true;
    }
    return false;
}

function checkDownModel() {
    var downmodel = $("#down-model-input").val();
    if(downmodel == '')
    {
        tipsMsg('downmodelnone');
        return false;
    }

    if(downmodel == '1' || downmodel == '3')
    {
        var earlydown21 = $("#earlydown21").val();
        var earlydown18 = $("#earlydown18").val();
        if(earlydown18 == '' || earlydown21 == '')
        {
            tipsMsg('downmodelnum');
            return false;
        }

        if(!isNumber(earlydown21) || !isNumber(earlydown18))
        {
            tipsMsg('downmodelnumerror');
            return false;
        }

    }

    if(downmodel == '2' || downmodel == '3')
    {
        var middledown21 = $("#middledown21").val();
        var middledown18 = $("#middledown18").val();
        if(middledown18 == '' || middledown21 == '')
        {
            tipsMsg('downmodelnum');
            return false;
        }

        if(!isNumber(middledown21) || !isNumber(middledown18))
        {
            tipsMsg('downmodelnumerror');
            return false;
        }
    }

    return true;
}

function checkIvfError() {
    var male = $("#ivf-male-input").val();
    var female = $("#ivf-female-input").val();

    if(male==2 || female == 2)
    {
        tipsMsg('ivferror');
        return false;
    }

    return true;
}

function checkIvf() {
    var ivf = $("#ivf-input").val();
    var male = $("#ivf-male-input").val();
    var female = $("#ivf-female-input").val();

    if(ivf.length ==0)
    {
        tipsMsg('ivfnone');
        return false;
    }

    if(male == '')
    {
        tipsMsg('ivfmalenone');
        return false;
    }

    if(female == '')
    {
        tipsMsg('ivffemalenone');
        return false;
    }

    if(male==2 || female == 2)
    {
        tipsMsg('ivferror');
        return false;
    }

    if(!checkIvfRemarkNone(ivf)) return false;
    if(!checkIvfRemark(ivf)) return false;

    return true;
}


function checkIvfRemark(ivf)
{
    var ivfRemark1 = $("#ivfRemark-1").val().trim();
    var ivfRemark2 = $("#ivfRemark-2").val().trim();
    var ivfRemark3 = $("#ivfRemark-3").val().trim();
    var ivfRemark4 = $("#ivfRemark-4").val().trim();
    if(ivf === '1')
    {
        if(ivfRemark1 === '2')  //3胎
        {
            tipsMsg('ivfmore');
            return false;
        }
        if(ivfRemark1 === '1')  //2胎
        {
            if(ivfRemark2 === '1')
            {
                tipsMsg('ivferror');
                return false;
            }
            if(ivfRemark2 === '2')
            {
                if(ivfRemark3 === '0')
                {
                    tipsMsg('ivflose');
                    return false;
                }
                if(ivfRemark4 === '0')
                {
                    tipsMsg('ivfstop');
                    return false;
                }
            }
        }
    }
    return true;
}

function checkIvfRemarkNone(ivf){
    var ivfRemark1 = $("#ivfRemark-1").val().trim();
    var ivfRemark2 = $("#ivfRemark-2").val().trim();
    var ivfRemark3 = $("#ivfRemark-3").val().trim();
    var ivfRemark4 = $("#ivfRemark-4").val().trim();

    if(ivf === '1')
    {
        if(ivfRemark1 === '')
        {
            tipsMsg('ivfremark1none');
            return false;
        }

        if(ivfRemark1 === '1' && ivfRemark2 === '')
        {
            tipsMsg('ivfremark2none');
            return false;
        }

        if(ivfRemark2 === '2' && ivfRemark3 === '')
        {
            tipsMsg('ivfremark3none');
            return false;
        }

        if(ivfRemark2 === '2' && ivfRemark4 === '')
        {
            tipsMsg('ivfremark4none');
            return false;
        }
    }

    return true;
}


function genIvfRemark() {
    var ivfRemark1 = $("#ivfRemark-1").val().trim();
    var ivfRemark2 = $("#ivfRemark-2").val().trim();
    var ivfRemark3 = $("#ivfRemark-3").val().trim();
    var ivfRemark4 = $("#ivfRemark-4").val().trim();
    var ivfRemark = "";
    if(ivfRemark1 !== '') ivfRemark += ivfRemark1;
    if(ivfRemark2 !== '') ivfRemark += ivfRemark2;
    if(ivfRemark3 !== '') ivfRemark += ivfRemark3;
    if(ivfRemark4 !== '') ivfRemark += ivfRemark4;
    $("#ivfRemark").val(ivfRemark);
}

function checkIsBadInput(obj, msg) {
    // $(obj).val($(obj).val().replace(/[^0-9]/g,''));
    alert($(obj).text());
}


function checkMobile(mobile){
    // alert('onchange');
    var m=$.trim($("#"+mobile).val());

    if( (/^16\d{9}$/.test( m )) | (/^19\d{9}$/.test( m )) | (/^13\d{9}$/.test( m )) | (/^15\d{9}$/.test( m ) ) | (/^18\d{9}$/.test( m ))  | (/^17\d{9}$/.test( m )) | (/^14\d{9}$/.test( m )) ){
        return true;
    }
    tipsMsg(mobile);
    return false;
}

function checkMobileNone(mobile)
{
    var m=$.trim($("#"+mobile).val());
    if(m.length ==0)
    {
        tipsMsg(mobile + 'none');
        return false;
    }

    return true;
}

function checkIdNumberNone(idnumber)
{
    var text = $.trim($("#"+idnumber).val());
    if(text.length == 0)
    {
        tipsMsg('idnumbernone');
        return false;
    }
    return true;
}

var regIdCard=/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;

function checkPassport(number){
    var str=number;
    var Expression=/(P\d{7})|(G\d{8})/;
    var objExp=new RegExp(Expression);

    if(objExp.test(str)==true){
        return true;
    }else{
        return false;
    }
};

function checkIdNumber(idnumber) {
    var text = $.trim($("#" + idnumber).val());
    var type = $("#idType").val();
    if ( type === '0' && checkIdcard(text) !== 'ok'){
        //alert("length " + text.length);
        tipsMsg('idnumber');
        return false;
    }

    if( type === '1' && !checkPassport(text))
    {
        tipsMsg('passport');
        return false;
    }

    if(type === '0')
    {
        var age = readAgeById(text);
        $("#age").val(age);
    }
    return true;
}

function checkGttWeek(gttWeek)
{
    var text = $.trim($("#"+gttWeek).val());
    var flag = $("#yunzh").data("flag");

    if(text.length == 0)
    {
        tipsMsg('gttweeknone');
        return false;
    }

    if( !checkNumber(gttWeek, 11, 41))
    {
        tipsMsg('gttweek');
        $("#gttWeek").css('color','red');
        $("#yunzh-tips").css('display','inline');
        return false;
    }
    else
    {
        $("#gttWeek").css('color','#333');
        $("#yunzh-tips").css('display','none');
    }

    if(text>=23 && flag==0)
    {
        tipsMsg('gttweeklarge');
        $("#yunzh").data("flag","1");
        return false;
    }
    return true;
}

function checkGttDay(gttDay)
{
    var text = $.trim($("#"+gttDay).val());
    if(text.length == 0)
    {
        tipsMsg('gttdaynone');
        return false;
    }

    if( text < 0 || text > 6  || text.length > 1 )
    {
        tipsMsg('gttday');
        $("#gttDay").css('color','red');
        $("#yunzh-tips").css('display','inline');
        return false;
    }
    else
    {
        $("#gttDay").css('color','#333');
        $("#yunzh-tips").css('display','none');
    }

    return true;
}

function checkNumber(num ,min,max){
    var n=$.trim($("#"+num).val());
    if( /^[1-9](\d+)?$/.test( n ) ){
        if(n>min && n<max)return true;
    }
    return false;
}

function checkWeigth(weight)
{
    var text = $.trim($("#"+weight).val());
    $("#weight").css('color','#333');
    $("#weight-tips").css('display','none');

    if(text.length == 0)
    {
        $("#weight").css('color','red');
        $("#weight-tips").css('display','inline');
        tipsMsg('weightnone');
        return false;
    }

    roundNum("#weight");

    if(!checkNumber(weight, 0 ,100))
    {
        $("#weight").css('color','red');
        $("#weight-tips").css('display','inline');
        tipsMsg('weight');
        return false;
    }

    return true;
}

function checkLocation()
{
    var town_text = $.trim($("#town-input").val());
    //var address_text = $.trim($("#address-input").val());

    if(town_text.length == 0 )
    {
        tipsMsg('location');
        return false;
    }
    return true;
}

function checkBscan()
{
    var text = $.trim($("#bscan-input").val());
    if(text.length == 0)
    {
        tipsMsg('bscannone');
        return false;
    }

    if(text == 2)
    {
        tipsMsg('bscan_2');
        return false;
    }

    if(text == 3)
    {
        tipsMsg('bscan_3');
        return false;
    }

    if(text == 4)
    {
        tipsMsg('bscan_4');
        return false;
    }

    if(text == 1)   //双胎正常,不出具补充报告
    {
        var needOtherReport = $("#needOtherReport").val();
        if(needOtherReport!=='')$("#needOtherReport").val(0);
    }

    return true;
}

function checkOption(option)
{

    var value = $.trim($("#"+option+"-input").val());
    console.log('opton: ' + $("#"+option+"-input").val());
    if(value.length == 0)
    {
        tipsMsg(option+"none");
        return false;
    }

    if(value == 1)
    {
        tipsMsg(option+"yes");
        return false;
    }
    return true;
}

function checkHys()
{
    var ges = $("#hysGes").val();
    var abo = $("#hysAbo").val();
    var lab = $("#hysLab").val();

    if($.trim(ges).length > 0)
    {
        if(ges < 1 || ges > 10)
        {
            tipsMsg('ges');
            return false;
        }
    }

    if($.trim(abo).length > 0)
    {
        if(abo < 0 || abo > 10)
        {
            tipsMsg('abo');
            return false;
        }
    }


    if($.trim(lab).length > 0)
    {
        if(lab < 0 || lab >10)
        {
            tipsMsg('lab');
            return false;
        }
    }


    return true;
}

//浦西:410728001 ,南浦: 410728003, 浦东: 410728002, 魏庄 410728103, 浦北 410728004, 丁栾 410728101, 樊相 410728102
function townValueMap(townCode)
{
    var townValue = "";
    switch (townCode)
    {
        case "410728001":
            townValue = "浦西";
            break;
        case "410728002":
            townValue = "浦东";
            break;
        case "410728003":
            townValue = "南浦";
            break;
        case "410728004":
            townValue = "浦北";
            break;
        case "410728101":
            townValue = "丁栾";
            break;
        case "410728102":
            townValue = "樊相";
            break;
        case "410728103":
            townValue = "魏庄";
            break;
        case "410728104":
            townValue = "恼里";
            break;
        case "410728105":
            townValue = "常村";
            break;
        case "410728106":
            townValue = "赵堤";
            break;
        case "410728202":
            townValue = "芦岗";
            break;
        case "410728203":
            townValue = "孟岗";
            break;
        case "410728204":
            townValue = "苗寨";
            break;
        case "410728205":
            townValue = "方里";
            break;
        case "410728206":
            townValue = "武邱";
            break;
        case "410728208":
            townValue = "佘家";
            break;
        case "410728209":
            townValue = "张三寨";
            break;
        case "410728210":
            townValue = "满村";
            break;

        default:
            break;
    }
//    console.log("townValue " + townValue);
    return townValue;
}

function cityCodeNameMap(code)
{
    var value = "";
    switch (code)
    {
        case "4419":
            value = "东莞市";
            break;
        case "4413":
            value = "惠州市";
            break;
        case "4403":
            value = "深圳市";
            break;

        default:
            break;
    }
    return value;
}

//ivf value map
//1:正常2:异常0:未知
function ivfMap(ivf)
{
    var ivfValue;
    switch (ivf)
    {
        case 1:
            ivfValue = "正常";
            break;
        case 2:
            ivfValue = "异常";
            break;
        case 0:
            ivfValue = "未做";
            break;
        default:
            break;
    }
    return ivfValue;
}

//downModel map
//唐筛模式：0 未做；1 早孕筛查；2 中孕筛查；3 早中孕期联合筛查
function downModelMap(downModel)
{
    var downModelValue;
    switch (downModel)
    {
        case 0:
            downModelValue = "未做";
            $("#downModelSubEarly").css('display','none');
            $("#downModelSubMiddle").css('display','none');
            break;
        case 1:
            downModelValue = "早期筛查";
            $("#downModelSubEarly").css('display','block');
            $("#downModelSubMiddle").css('display','none');
            break;
        case 2:
            downModelValue = "中期筛查";
            $("#downModelSubEarly").css('display','none');
            $("#downModelSubMiddle").css('display','block');
            break;
        case 3:
            downModelValue = "早中期联合筛查";
            $("#downModelSubEarly").css('display','block');
            $("#downModelSubMiddle").css('display','block');
            break;

        default:
            break;
    }
    return downModelValue;
}


//radio选择
//注意:使用前提是0:否, 1:是
function radioSelect(radioId, radioValue)
{
    if(radioValue == 0)
    {
        radioNo(radioId);
    }
    else if(radioValue == 1)
    {
        radioYes(radioId);
    }
}

//选填信息检测,0:未填 1:已填
function optionCheck(optionValue)
{
    if(typeof(optionValue) == "undefined")
    {
        return 0;
    }
    else
    {
        return 1;
    }
}

//选填信息检测,0:未填 1:已填
function optionHysCheck(optionValue)
{
    if(typeof(optionValue) == "undefined" || optionValue == -1)
    {
        return 0;
    }
    else
    {
        return 1;
    }
}

function radioComSelect(radioId, radioValue)
{
    if(radioValue == 0)
    {
        radioNoCom(radioId);
    }
    else if(radioValue == 1)
    {
        radioYesCom(radioId);
    }
}

//B超值映射
// B超结果： 正常(单胎活) 0；  正常(双胎活)1； 异常(单胎)2； 异常(双胎)3；  正常(多胎活) 4；  异常(多胎) 5
function bscanMap(bscan)
{
    var bscanValue;
    switch (bscan)
    {
        case 0:
            bscanValue = "单胎正常";
            break;
        case 1:
            bscanValue = "双胎正常";
            break;
        case 2:
            bscanValue = "单胎异常";
            break;
        case 3:
            bscanValue = "双胎异常";
            break;
        case 4:
            bscanValue = "多胎";
            break;
        default:
            break;
    }
    return bscanValue;
}



function getFswidByCode(code) {
    var i = 0;
    var data = JSON.parse(hospitalData);
    for(i in data)
    {
        var item = data[i];
        if(item.code == code)
        {
            return item.bgiRegion.busKey;
        }
    }
}

function genAreaText(province, city, county) {
    if(province == "") return "";
    var areaText = "";
    var provinceText = province+"0000";
    var cityText = city+"00";
    var countyText = county + "";
    $.each(provs_data,function () {
        if(this.value == provinceText)
        {
            areaText+=this.text;
        }
    });

    $.each(citys_data[provinceText],function () {
        if(this.value == cityText)
        {
            areaText+=",";
            areaText+=this.text;
        }
    });

    $.each(dists_data[cityText],function () {
        if(this.value == countyText)
        {
            areaText+=",";
            areaText+=this.text;
        }
    });

    return areaText;
}

function genAreaValue(province, city, county) {
    var areaValue = "";
    if(province != "") areaValue+=province;
    if(city != "")
    {
        areaValue+=",";
        areaValue+=city;
    }
    if(county != "")
    {
        areaValue+=",";
        areaValue+=county;
    }
    return areaValue;
}

function queryHospital(customerCode, hospitalData) {
    var hospital = "";
    if(hospitalData == "") return "";
    var jsonObj = JSON.parse(hospitalData);
    $.each(jsonObj,function () {
        if(this.code === customerCode)
        {
            hospital = this.name;
            return;
        }
    });
    return hospital;
}

function queryCity(customerCode) {
    var cityName = "";
    var jsonObj = JSON.parse(hospitalData);
    // console.log(jsonObj);
    $.each(jsonObj,function () {
        if(this.code === customerCode)
        {
            var cityCode = this.city+"00";
            var proviceCode = this.province+"0000";
            $.each(citys_data[proviceCode],function () {
                if(this.value == cityCode)
                {
                    cityName = this.text;
                    return;
                }
            });
            return;
        }
    });
    return cityName;
}

function setIdType(idType) {
    var typeText = "";
    if(idType === 0) typeText = "身份证";
    if(idType === 1) typeText = "护照";
    $("#idType-value").text(typeText);
    $("#idType-value").css("color", "#333");
    $("#idtype-"+idType).addClass("selected");
    $("#idType-line").show();
    $("#idNumberDiv").show();
}

function parseIvfRemark() {
    var ivfRemark = $("#ivfRemark").val();
    if(ivfRemark==="0")
    {
        $("#ivfRemark-1").val(0);
        $("#ivfRemarkSel-1 img").first().attr("src", "./images/order/radio-blue.png");
    }
    if(ivfRemark==="10")
    {
        $("#ivfRemark-1").val(1);
        $("#ivfRemark-2").val(0);
        $("#ivfRemarkSel-2").show();
        $("#ivfRemarkSel-1 img").eq(1).attr("src","./images/order/radio-blue.png");
        $("#ivfRemarkSel-2 img").first().attr("src", "./images/order/radio-blue.png");
    }
    if(ivfRemark==="1211")
    {
        $("#ivfRemark-1").val(1);
        $("#ivfRemark-2").val(2);
        $("#ivfRemark-3").val(1);
        $("#ivfRemark-4").val(1);
        $("#ivfRemarkSel-2").show();
        $("#ivfRemarkSel-3").show();
        $("#ivfRemarkSel-1 img").eq(1).attr("src","./images/order/radio-blue.png");
        $("#ivfRemarkSel-2 img").eq(2).attr("src", "./images/order/radio-blue.png");
        $("#ivf-sub1-yes").attr("src","./images/order/radio-blue.png");
        $("#ivf-sub2-yes").attr("src","./images/order/radio-blue.png");
    }
}



function setRemark(type,value) {
    if(value === '' || typeof(value) === 'undefined') return;

    $("#"+type+"-remark-note").hide();
    $("#"+type+"-remark-div").show();
    if(type === 'ivf')
    {
        parseIvfRemark();
    }
}


function setGestation(order) {
    $('#gestation-sel-note').hide();
    var gestaticonValue = '';
    if(order.zrsy==1) gestaticonValue = '自然受孕';
    else if(order.cpl==1) gestaticonValue = '促排卵';
    else if(order.gnrgsj==1) gestaticonValue = '宫内人工授精';
    else gestaticonValue = '以上均无'
    $('#gestation-value').text(gestaticonValue);
    $('li[data-value='+gestaticonValue+']').addClass('selected');
}

function setValues()
{
    setIdType(orderInfo.idType);
    $("#bscan-sel-note").hide();
    $("#ivf-male-sel-note").hide();
    $("#ivf-female-sel-note").hide();
    $("#down-sel-note").hide();
    setRemark('bscan', orderInfo.bscanRemark);
    setRemark('ivf', orderInfo.ivfRemark);
    setRemark('ivf-male', orderInfo.maleKarDetRemark);
    setRemark('ivf-female', orderInfo.femaleKarDetRemark);

    setGestation(orderInfo);

    $("#area-opt").val(genAreaText(orderInfo.province, orderInfo.city, orderInfo.county));
    $("#area-value").val(genAreaValue(orderInfo.province, orderInfo.city, orderInfo.county));

    $("#lastPeriod").text(orderInfo.lastMenstrualPeriod);




    $("#bscan-input").val(orderInfo.bscan);
    $("#bscan-value").text(bscanMap(orderInfo.bscan));
    $("#bscan-"+orderInfo.bscan).addClass("selected");
    selectedBscanId = "bscan-" + orderInfo.bscan;

    radioSelect("shuxue", orderInfo.allogBloodTrans);
    radioSelect("yizhi", orderInfo.organTrans);
    radioSelect("mianyi", orderInfo.immunotherapy);
    radioSelect("gxb", orderInfo.apsc);

    //选填信息
    // 人工授精, 男女方核型检测
    if(optionCheck(orderInfo.ivf) == 1)
    {
        radioComSelect('ivf', orderInfo.ivf);
        $("#ivf-male-input").val(orderInfo.maleKarDet);
        $("#ivf-male-value").text(ivfMap(orderInfo.maleKarDet));
        $("#ivf-male").css('color','#333');
        $("#ivf-"+orderInfo.maleKarDet).addClass("selected");
        selectedIVFId = "ivf-" + orderInfo.maleKarDet;

        $("#ivf-female-input").val(orderInfo.femaleKarDet);
        $("#ivf-female-value").text(ivfMap(orderInfo.femaleKarDet));
        $("#ivf-female").css('color','#333');
        $("#ivf-f-"+orderInfo.femaleKarDet).addClass("selected");
        selectedFemaleIVFId = "ivf-f-" + orderInfo.femaleKarDet;
    }

    //畸形胎儿
    if(optionCheck(orderInfo.deformed) == 1)
    {
        radioComSelect('deformed', orderInfo.deformed);
    }

    if(optionHysCheck(orderInfo.hysGes) == 1)
    {
        $("#hysGes").val(orderInfo.hysGes);
    }

    if(optionHysCheck(orderInfo.hysAbo) == 1)
    {
        $("#hysAbo").val(orderInfo.hysAbo);
    }

    if(optionHysCheck(orderInfo.hysLab) == 1)
    {
        $("#hysLab").val(orderInfo.hysLab);
    }

    //唐筛模式
    if(optionCheck(orderInfo.downModel) == 1)
    {
        $("#down-model-input").val(orderInfo.downModel);
        $("#downModel-value").text(downModelMap(orderInfo.downModel));
        $("#down-"+orderInfo.downModel).addClass("selected");
        selectedDownModelId = "down-" + orderInfo.downModel;
    }

    // 母血清筛查风险 21
    if(optionCheck(orderInfo.earlySerologicResult21) == 1)
    {
        $("#earlydown21").val(orderInfo.earlySerologicResult21);
    }

    // 母血清筛查风险 18
    if(optionCheck(orderInfo.earlySerologicResult18) == 1)
    {
        $("#earlydown18").val(orderInfo.earlySerologicResult18);
    }

    if(optionCheck(orderInfo.earlyNtd) == 1)
    {
        $("#earlyntd").val(orderInfo.earlyNtd);
    }

    // 母血清筛查风险 21
    if(optionCheck(orderInfo.middleSerologicResult21) == 1)
    {
        $("#middledown21").val(orderInfo.middleSerologicResult21);
    }

    // 母血清筛查风险 18
    if(optionCheck(orderInfo.middleSerologicResult18) == 1)
    {
        $("#middledown18").val(orderInfo.middleSerologicResult18);
    }

    if(optionCheck(orderInfo.middleNtd) == 1)
    {
        $("#middlentd").val(orderInfo.middleNtd);
    }

}


function confirmOrder() {
    $("#actform").attr("action", '/order/normal/confirm.do');
    $("#actform").submit();
}

function transX(obj) {
    var id = $.trim($(obj).val());
    var patten = /^(\d){17}x$/ig;
    var patten1 = /^p/ig;
    var patten2 = /^g/ig;
    if(patten.test(id))
    {
        var transId = id.replace("x","X");
        $(obj).val(transId);
    }
    if(patten1.test(id))
    {
        var transId = id.replace("p","P");
        $(obj).val(transId);
    }
    if(patten2.test(id))
    {
        var transId = id.replace("g","G");
        $(obj).val(transId);
    }
}

var selectedIdType = "NA";
function selIdType(obj, idSel) {
    var id = obj.id;
    var value = $("#"+id).data("value");
    var input = $("#"+id).data("input");
    if( id != selectedIdType)
    {
        $("#"+id).addClass("selected");
        $("#"+selectedIdType).removeClass("selected");
        selectedIdType = id;
        $("#idnumber").val('');
    }

    $("#idType-value").text(value);
    $("#idType-value").css('color', '#333');
    $("#idType").val(input);
    $("#idType-line").show();
    $("#idNumberDiv").show();
    closeSelTips(idSel);
}

function checkAge() {
    var age = parseInt($("#age").val().trim());
    if(age <= 0)
    {
        tipsMsg('age');
        return false;
    }
    return true;
}

function checkAgeNone() {
    var age = $("#age").val().trim();
    if(age === '')
    {
        tipsMsg('agenone');
        return false;
    }
    return true;
}

function checkRemark(obj, type) {
    var trimNote = $.trim($(obj).val());
    $(obj).val(trimNote);
    var length = trimNote.length;
    if(length>300)
    {
        tipsMsg(type.replace('-','')+'remarklength');
        return false;
    }
    return true;
}

function showRemark(type) {
    $("#"+type+"-remark-div").show();
    $("#"+type+"-remark-note").hide();
}

function selectIvfRemark(obj, type) {
    var value = $(obj).data("value");

    var divObj = $(obj).parent(".serologic-result-div");
    $(divObj).find("img").attr("src", "./images/order/radio-def.png");
    $(obj).find("img").attr("src", "./images/order/radio-blue.png");
    $("#ivfRemark-"+type).val(value);

    if(type === "1")
    {
        if(value === 1)
        {
            $("#ivfRemarkSel-2").show();
        }
        else
        {
            $("#ivfRemarkSel-2").hide();
            $("#ivfRemarkSel-2 img").attr("src", "./images/order/radio-def.png");
            $("#ivfRemark-2").val("");
            $("#ivfRemarkSel-3").hide();
            $("#ivfRemark-3").val("");
            $("#ivfRemark-4").val("");
            $("#ivfRemarkSel-3 img").attr("src", "./images/order/radio-def.png");
        }

        if(value === 2)
        {
            tipsMsg('ivfmore');
            $(obj).find("img").attr("src", "./images/order/radio-red.png");
        }
    }

    if(type === "2")
    {
        if(value === 2)
        {
            $("#ivfRemarkSel-3").show();
        }
        else
        {
            $("#ivfRemarkSel-3").hide();
            $("#ivfRemark-3").val("");
            $("#ivfRemark-4").val("");
            $("#ivfRemarkSel-3 img").attr("src", "./images/order/radio-def.png");
        }

        if(value === 1)
        {
            $(obj).find("img").attr("src", "./images/order/radio-red.png");
            tipsMsg('ivferror');
        }
    }
}

function radioIvfRemarkYes(id, type) {
    $("#" + id + "-yes").attr("src", "./images/order/radio-blue.png");
    $("#" + id + "-no").attr("src", "./images/order/radio-def.png");
    $("#ivfRemark-" + type).val(1);
}

function radioIvfRemarkNo(id, type) {
    $("#" + id + "-yes").attr("src", "./images/order/radio-def.png");
    $("#" + id + "-no").attr("src", "./images/order/radio-red.png");
    $("#ivfRemark-" + type).val(0);

    if(type === '3')
    {
        tipsMsg('ivflose');
    }

    if(type === '4')
    {
        tipsMsg('ivfstop');
    }
}

function useCoupon(){
    openSelectTip('couponSelDiv')
    queryCoupon()
}
//选择优惠券
function selCoupon(obj){
    var id = obj.id;
    var value = $("#"+id).data("value");
    var status = $("#"+id).data("status");
    var idCard = $("#"+id).data("idCard");
    $('#idnumber').val(idCard);
    var productCode = $('#'+id).data("code");
    if(status != 1) return;
    if(productCode!='BS0003') return;
    setIdType(0);
    var input_value = $("#"+id).data("input");
    couponNum=input_value
    hasCoupon(true)
    //关闭浮层
    closeSelTips('couponSelDiv');

}
//判断是否已选择优惠券
function hasCoupon(flag){
    if(flag===true){
        $('#coupon_title').text('已使用免费券')
        $('#coupon_icon').show()
        $('#idnumber').val(personInfo.id)
        $('#name').val(personInfo.name)

    }else{
        $('#coupon_title').text('点击使用免费券')
        $('#coupon_icon').hide()
    }

}

//加载优惠券
function queryCoupon(){
    doQueryCoupon();
    var rows=[{type:1,couponNum:'11B2232','couponName':'长沙市民生项目NIPT免费券',couponDesc:'',barcodeImg:'',idCard:'4301081984022311',status:0},{type:1,couponNum:'11B2232','couponName':'长沙市民生项目NIPT免费券',couponDesc:'',barcodeImg:'',idCard:'4301081984022311',status:0},{type:1,couponNum:'11B2232','couponName':'长沙市民生项目NIPT免费券',couponDesc:'',barcodeImg:'',idCard:'4301081984022311',status:0},]
    var cusStr = '';
}
var personInfo={}
function doQueryCoupon(){//加载优惠券网络请求
    $.ajax({
        type:"post",
        url:BASEURL+"/csfy/user/getPresonInfo.do",
        data:{},
        dataType:"json",
        success:function (data) {
            if(data.code == 200){
                var info = data.data
                personInfo.id=info.id;
                personInfo.name=info.name;
                var rows = info.couponInfos;
                var cusStr = '';
                if(rows) {
                    for(var key in rows){
                        var obj = rows[key];
                        obj.idCard=personInfo.id;
                        // if(obj.type===2) continue;
                        var couponStatus = obj.status;
                        var statusTip = '已审核(可用)';
                        var liStatus = couponStatus==1?1:0;
                        if(obj.productCode!='BS0003') {
                            statusTip = '已审核';
                            liStatus=0
                        }
                        if(couponStatus==0){
                            statusTip = '未审核';
                        }else if(couponStatus==-1){
                            statusTip = '审核不通过';
                        }else if(couponStatus==2){
                            statusTip = '已使用';
                        }

                        var str = '<li style="height:auto;" id="coupon-'+key+'" data-idCard="'+obj.id+'" data-code="'+obj.productCode+'" data-input="'+obj.couponNum+'" data-status="'+obj.status+'" data-value="'+obj.couponName+'" class="sel-info coupon_sel_'+liStatus+'" onclick="selCoupon(this);"><div class="coupon_sel_info"><div class="coupon_sel_name">'+obj.couponName+'</div><div class="coupon_sel_tip">限身份证号码为'+obj.id+'使用--'+statusTip+'</div></div><div class="coupon_sel_iconbox"><div class="coupon_sel_status_'+couponStatus+'" ></div></div><div style="clear: both; height:60px;width:240px;"><img style="display:block;width:100%;height:100%;" src="'+obj.couponImg+'"></div></li><li><div class="input-line"></div></li>';
                        cusStr += str;
                    }
                    $('#couponBox').html(cusStr);
                    //获取在优惠券列表存的优惠券类型和优惠券编码
                    if(sessionStorage.getItem('juanInfo')){
                        var juanInfo = JSON.parse(sessionStorage.getItem('juanInfo'));
                        if(juanInfo.type == 7){
                            couponNum = juanInfo.couponNum;
                            setIdType(0);
                            hasCoupon(true);
                        }
                    }
                } else {
                    var str = '<li style="text-align:center;color: #00afee;" id="coupon-'+ 0 +'" data-input="'+''+'" data-value="'+''+'" class="sel-info" onclick="selCoupon(this);">'+'您还没有免费券,您可以在公众号点击菜单我的服务-->领取免费券'+'</li><div class="input-line"></div>';
                    $('#couponBox').html(str);
                }
            }else {
                alert(data.msg);
            }
        }
    });
}

function initUrlInfo(){//截取页面url获取参数
    var url = location.search;
    url = decodeURI(url);
    url = decodeURI(url);
    var Request = new Object();
    if(url.indexOf("?")!=-1){
        var str = url.substr(1);//去掉?号
        strs = str.split("&");
        for(var i=0;i<strs.length;i++){
            var key = strs[i].split("=")[0];
            var value = unescape(strs[i].split("=")[1]);
            Request[key]=value;
            var keyId = '#' + key;
            $(keyId).text(value);
        }
    }
    couponNum = Request['couponNum']||'';
    if(couponNum){
        hasCoupon(true)
    }else{
        hasCoupon(false)
    }
}